package com.example.manu_facturer_orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manu_facturer_orders.pojo.PageResult;
import com.example.manu_facturer_orders.pojo.ServiceProviderVO;
import com.example.manu_facturer_orders.service.ServiceProviderService;
import commons.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: tobed
 * @date: 2022/9/13
 * @time: 16:58
 */
@RestController
@RequestMapping("serviceProvider")
public class ServiceProviderController {

    @Autowired
    ServiceProviderService serviceProviderService;

    /**
     * 服务商全查
     * @param facilitatorCode
     * @param facilitatorName
     * @param signingType
     * @param pageResult
     * @return
     */
    @GetMapping("list")
    public Result list(
            @RequestParam String facilitatorCode,
            @RequestParam String facilitatorName,
            @RequestParam Integer signingType,
            PageResult pageResult){
        Page<ServiceProviderVO> list = serviceProviderService.list(facilitatorCode, facilitatorName, signingType, new Page<>(pageResult.getPageNum(), pageResult.getPageSize()));
        return Result.success(list);
    }

    /**
     * 解约服务商
     * @param id
     * @return
     */
    @DeleteMapping("terminationService")
    public Result terminationService(@Param("id") Integer id){
        Result result = serviceProviderService.terminationService(id);
        return result;
    }

    /**
     * 启用或停用服务商
     * @param id
     * @param signingType
     * @return
     */
    @GetMapping("openOrClose")
    public Result openOrClose(
            @RequestParam Integer id,
            @RequestParam Integer signingType){
        Result result = serviceProviderService.openOrClose(id,signingType);
        return result;
    }

}
